<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/20 12:11
 */

namespace module\chat\front\form;

use module\chat\enum\RoleEnum;
use module\chat\model\Category;
use mof\enum\StatusEnum;
use mof\front\Form;
use mof\Model;
use mof\utils\DictArray;
use mof\utils\ElementData;

class AssistantForm extends Form
{
    protected array $validate = [
        'param' => [
            'category_id', 'name', 'icon', 'intro', 'listorder/d', 'status/d', 'config/a',
            'welcome', 'questions', 'placeholder'
        ],
        'rule'  => [
            'category_id|分类'     => 'require|number',
            'name|标题'            => 'require|length:2,30',
            'intro|描述'           => 'length:0,200',
            //'icon|图标'     => 'require|storage',
            'status|状态'          => 'require|in:0,1',
            'config|配置'          => 'require|array',
            'welcome|开场白'       => 'max:200',
            'question|示例问题'    => 'max:300',
            'placeholder|输入提示' => 'max:100',
        ],
    ];

    protected function elements(Model $model = null): array
    {
        return [
            [
                "label"   => "助手分类",
                "prop"    => "category_id",
                "value"   => $model['category_id'] ?? '',
                "type"    => "select",
                "options" => ElementData::make(Category::getListByType(RoleEnum::ASSISTANT->value))
                    ->toSelectOptions('name', 'id')
            ],
            [
                "label" => "助手标题",
                "prop"  => "name",
                "value" => $model['name'] ?? '',
            ],
            [
                "label" => "助手简介",
                "prop"  => "intro",
                "value" => $model['intro'] ?? '',
            ],
            [
                "label" => "助手图标",
                "prop"  => "icon",
                "value" => $model['icon'] ?? '',
                "type"  => "upload:image"
            ],
            [
                "label" => "前置描述",
                "prop"  => "config.template",
                "type"  => "textarea",
                "value" => $model['config']['template'] ?? '',
                "rows"  => 4,
                "intro" => '变量说明：<span title="用户输入的内容">{prompt}</span>',
            ],
            [
                "label" => "开场白",
                "prop"  => "welcome",
                "type"  => "textarea",
                "value" => $model['welcome'] ?? '',
                "rows"  => 4,
                "intro" => '进入对话页面时显示的欢迎语',
            ],
            [
                "label" => "示例问题",
                "prop"  => "questions",
                "type"  => "textarea",
                "value" => $model['questions'] ?? '',
                "rows"  => 4,
                "intro" => '每行一个例子',
            ],
            [
                "label" => "输入提示",
                "prop"  => "placeholder",
                "value" => $model['placeholder'] ?? '',
                "intro" => '输入框提示语，如：请输入您的问题、请描述您要查询的问题等'
            ],
            [
                "label"   => "状态",
                "prop"    => "status",
                "value"   => $model['status'] ?? 1,
                "type"    => "select",
                "options" => StatusEnum::toDict()->toElementData()->toSelectOptions(),
                "colSpan" => 12
            ],
            [
                "label"   => "排序",
                "prop"    => "listorder",
                "value"   => $model['listorder'] ?? 0,
                "colSpan" => 12
            ],
        ];
    }
}